package com.xjtu.mybatisplus.web.controller;

import com.xjtu.mybatisplus.common.result.PageResult;
import com.xjtu.mybatisplus.model.domain.Article;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.xjtu.mybatisplus.common.JsonResponse;
import com.xjtu.mybatisplus.service.FavoriteService;
import com.xjtu.mybatisplus.model.domain.Favorite;

import java.util.List;


/**
 *
 *  前端控制器
 *
 *
 * @author lsong
 * @since 2023-12-27
 * @version v1.0
 */
@RestController
@RequestMapping("/api/favorite")
@Api(tags = "点赞管理")
public class FavoriteController {

    private final Logger logger = LoggerFactory.getLogger( FavoriteController.class );

    @Autowired
    private FavoriteService favoriteService;

    @GetMapping("fav")
    @ApiOperation("用户点赞文章/取消点赞文章")
    public JsonResponse changeFavorite(@RequestParam(required = true) Long userId, @RequestParam(required = true) Long articleId) {
        return favoriteService.setFavorite(userId, articleId);
    }
    @GetMapping("list")
    @ApiOperation("我点赞的文章")
    public JsonResponse<PageResult> getFavList(@RequestParam(required = true) Long userId, @RequestParam(required = true)Integer page, @RequestParam(required = true) Integer size) {
        return favoriteService.getListById(userId, page, size);
    }

    @GetMapping("status")
    @ApiOperation("查看文章点赞信息")
    public JsonResponse getStatus(@RequestParam(required = true) Long userId, @RequestParam(required = true) Long articleId) {
        return favoriteService.getFavStatusById(articleId, userId);
    }



//    /**
//    * 描述：根据Id 查询
//    *
//    */
//    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
//    @ResponseBody
//    public JsonResponse getById(@PathVariable("id") Long id)throws Exception {
//        Favorite  favorite =  favoriteService.getById(id);
//        return JsonResponse.success(favorite);
//    }
//
//    /**
//    * 描述：根据Id删除
//    *
//    */
//    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
//    @ResponseBody
//    public JsonResponse deleteById(@PathVariable("id") Long id) throws Exception {
//        favoriteService.removeById(id);
//        return JsonResponse.success(null);
//    }
//
//
//    /**
//    * 描述：根据Id 更新
//    *
//    */
//    @RequestMapping(value = "", method = RequestMethod.PUT)
//    @ResponseBody
//    public JsonResponse updateFavorite(Favorite  favorite) throws Exception {
//        favoriteService.updateById(favorite);
//        return JsonResponse.success(null);
//    }
//
//
//    /**
//    * 描述:创建Favorite
//    *
//    */
//    @RequestMapping(value = "", method = RequestMethod.POST)
//    @ResponseBody
//    public JsonResponse create(Favorite  favorite) throws Exception {
//        favoriteService.save(favorite);
//        return JsonResponse.success(null);
//    }
}

